﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DBBase;
using System.IO;

using System.Reflection; // 引用这个才能使用Missing字段
using System.Xml;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Collections;
namespace Business
{
    public partial class TestLine : Form
    {


        ArrayList ccllx = new ArrayList();
        public int ijilu;
        public TestLine()
        {
            InitializeComponent();
           
            ijilu = 0;
            getcllxnew();
        }

        public void getcllxnew()
        {
            Query mquery = new Query();
            string sql;
            sql = string.Format(@"Select distinct DET_JCXH from Detects_SJA ");
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["DET_JCXH"].ToString().Trim().Length > 1)
                    {
                        ccllx.Add(dt.Rows[i]["DET_JCXH"].ToString().Trim());
                        ijilu++;
                    }
                }
            }
        }
        public void getneirong()
        {
            string sql = "";
            string sql2 = "";
            string sql3 = "";
            string sql4 = "";
            Query mquery = new Query();
            for (int i = 0; i < ijilu; i++)
            {
                sql = string.Format(@"Select AT_CLLX from Autos,Examines,Detects Where Examines.EXAMINE_ID=Detects.EXAMINE_ID and Examines.AT_ID=Autos.AT_ID and AT_CLLX like '%%{0}%%'", ccllx[i]);

                int izong = mquery.selectDBcount(sql);

                sql2 = string.Format(@"Select AT_CLLX from Autos,Examines,Detects Where Examines.EXAMINE_ID=Detects.EXAMINE_ID and Examines.AT_ID=Autos.AT_ID and AT_CLLX like '%%{0}%%' and DET_OK=1", ccllx[i]);

                int izong2 = mquery.selectDBcount(sql2);

                sql3 = string.Format(@"Select AT_CLLX from Autos,Examines,Detects Where Examines.EXAMINE_ID=Detects.EXAMINE_ID and Examines.AT_ID=Autos.AT_ID and AT_CLLX like '%%{0}%%' and DET_OK=1 and DET_ITERAT<1", ccllx[i]);

                int izong3 = mquery.selectDBcount(sql3);

                sql4 = string.Format(@"Select AT_CLLX from Autos,Examines,Detects Where Examines.EXAMINE_ID=Detects.EXAMINE_ID and Examines.AT_ID=Autos.AT_ID and AT_CLLX like '%%{0}%%' and DET_OK=1 and DET_ITERAT>0", ccllx[i]);

                int izong4 = mquery.selectDBcount(sql4);
            }
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            DataTable dtable = new DataTable("Rock");
            //set columns names
            dtable.Columns.Add("1", typeof(System.String));
            dtable.Columns.Add("2", typeof(System.String));
            dtable.Columns.Add("3", typeof(System.String));
            dtable.Columns.Add("4", typeof(System.String));
            dtable.Columns.Add("5", typeof(System.String));
            dtable.Columns.Add("6", typeof(System.String));
            dtable.Columns.Add("7", typeof(System.String));
            dtable.Columns.Add("8", typeof(System.String));
            dtable.Columns.Add("9", typeof(System.String));
            dtable.Columns.Add("10", typeof(System.String));

            Query mquery = new Query();
            string sql = "";
            string sql2 = "";
            string sql3 = "";
            string sql4 = "";
            string sql5 = "";
            string sql6 = "";
            string sql7 = "";
            string sql8 = "";
            DataRow drow = dtable.NewRow();
            for (int i = 0; i < ijilu; i++)
            {
                sql = string.Format(@"Select AT_CLLX from [dbo].[AUTO],Detects_SJA Where AUTO.AT_ID=Detects_SJA.AT_ID and DET_JCXH='{0}' and 
Detects_SJA.DET_DATE>'{1}' and Detects_SJA.DET_DATE<'{2}'", ccllx[i], date_kaishi.Value.ToShortDateString() + " 00:00:00", date_jieshu.Value.ToShortDateString() + " 23:59:59");

                int izong = mquery.selectDBcount(sql);


                sql2 = string.Format(@"Select AT_CLLX from [dbo].[AUTO],Detects_SJA Where AUTO.AT_ID=Detects_SJA.AT_ID and DET_JCXH='{0}' and 
Detects_SJA.DET_DATE>'{1}' and Detects_SJA.DET_DATE<'{2}' and DET_JYZJL=1", ccllx[i], date_kaishi.Value.ToShortDateString() + " 00:00:00", date_jieshu.Value.ToShortDateString() + " 23:59:59");

                int izong2 = mquery.selectDBcount(sql2);

                sql3 = string.Format(@"Select AT_CLLX from [dbo].[AUTO],Detects_SJA Where AUTO.AT_ID=Detects_SJA.AT_ID and DET_JCXH='{0}' and 
Detects_SJA.DET_DATE>'{1}' and Detects_SJA.DET_DATE<'{2}' and DET_JYCS=1 ", ccllx[i], date_kaishi.Value.ToShortDateString() + " 00:00:00", date_jieshu.Value.ToShortDateString() + " 23:59:59");

                int izong3 = mquery.selectDBcount(sql3);

                sql4 = string.Format(@"Select AT_CLLX from [dbo].[AUTO],Detects_SJA Where AUTO.AT_ID=Detects_SJA.AT_ID and DET_JCXH='{0}' and 
Detects_SJA.DET_DATE>'{1}' and Detects_SJA.DET_DATE<'{2}'and DET_JYZJL=1 and DET_JYCS=1", ccllx[i], date_kaishi.Value.ToShortDateString() + " 00:00:00", date_jieshu.Value.ToShortDateString() + " 23:59:59");

                int izong4 = mquery.selectDBcount(sql4);


                sql5 = string.Format(@"Select AT_CLLX from [dbo].[AUTO],Detects_SJA Where AUTO.AT_ID=Detects_SJA.AT_ID and DET_JCXH='{0}' and 
Detects_SJA.DET_DATE>'{1}' and Detects_SJA.DET_DATE<'{2}' and DET_JYCS=2 ", ccllx[i], date_kaishi.Value.ToShortDateString() + " 00:00:00", date_jieshu.Value.ToShortDateString() + " 23:59:59");

                int izong5 = mquery.selectDBcount(sql5);

                sql6 = string.Format(@"Select AT_CLLX from [dbo].[AUTO],Detects_SJA Where AUTO.AT_ID=Detects_SJA.AT_ID and DET_JCXH='{0}' and 
Detects_SJA.DET_DATE>'{1}' and Detects_SJA.DET_DATE<'{2}' and DET_JYZJL=1 and DET_JYCS=2", ccllx[i], date_kaishi.Value.ToShortDateString() + " 00:00:00", date_jieshu.Value.ToShortDateString() + " 23:59:59");

                int izong6 = mquery.selectDBcount(sql6);

                sql7 = string.Format(@"Select AT_CLLX from [dbo].[AUTO],Detects_SJA Where AUTO.AT_ID=Detects_SJA.AT_ID and DET_JCXH='{0}' and 
Detects_SJA.DET_DATE>'{1}' and Detects_SJA.DET_DATE<'{2}'  and DET_JYCS=3 ", ccllx[i], date_kaishi.Value.ToShortDateString() + " 00:00:00", date_jieshu.Value.ToShortDateString() + " 23:59:59");

                int izong7 = mquery.selectDBcount(sql7);

                sql8 = string.Format(@"Select AT_CLLX from [dbo].[AUTO],Detects_SJA Where AUTO.AT_ID=Detects_SJA.AT_ID and DET_JCXH='{0}' and 
Detects_SJA.DET_DATE>'{1}' and Detects_SJA.DET_DATE<'{2}' and DET_JYZJL=1 and DET_JYCS=3", ccllx[i], date_kaishi.Value.ToShortDateString() + " 00:00:00", date_jieshu.Value.ToShortDateString() + " 23:59:59");

                int izong8 = mquery.selectDBcount(sql8);


                drow = dtable.NewRow();
                // drow["1"] = string.Format("{0}","检测线1");ccllx[i]
                drow["1"] = ccllx[i];
                drow["2"] = string.Format("{0}", izong);
                drow["3"] = string.Format("{0}", izong2);
                drow["4"] = string.Format("{0}%", 100 * izong2 / (izong > 0 ? izong : 1));
                drow["5"] = string.Format("{0}", izong3);
                drow["6"] = string.Format("{0}%", 100 * izong4 / (izong3 > 0 ? izong3 : 1));
                drow["7"] = string.Format("{0}", izong5);
                drow["8"] = string.Format("{0}%", 100 * izong6 / (izong5 > 0 ? izong5 : 1));
                drow["9"] = string.Format("{0}", izong7);
                drow["10"] = string.Format("{0}%", 100 * izong8 / (izong7 > 0 ? izong7 : 1));

                dtable.Rows.Add(drow);
            }



            multiColHeaderDgv2.DataSource = dtable;
        }
     
       
    }
}
